package main

import "fmt"

/*
根据结构体中某个属性对结构体数组进行分组
*/
func main() {

	// 申明一个map，key为string类型，value 为结构体数组
	m := make(map[string][]student)

	stus := []student{
		{name: "ppr", age: 18},
		{name: "ppr", age: 20},
		{name: "ppr", age: 18},
		{name: "ppr", age: 20},
		{name: "测试", age: 23},
		{name: "博客", age: 28},
	}

	for _, stu := range stus {
		m[stu.name] = append(m[stu.name], stu)
	}
	for k, v := range m {
		fmt.Println(k, "=>", v)
	}
}

type student struct {
	name string
	age  int
}
